//
//  HOFaultCategoryEntity.m
//  微度报修
//
//  Created by foguo-mac-1 on 6/17/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HOFaultCategoryEntity.h"
#import "HOConstants.h"
#import "HOStaticDataMgr.h"
#import "HOUtils.h"

@implementation HOFaultCategoryEntity

@synthesize faultId;
@synthesize faultDetail;
- (instancetype)init
{
	self = [super init];
	if(self)
	{
		self.subTypes = [[[NSMutableArray alloc] init] autorelease];
	}
	return self;
}
 

- (void)parseDic:(NSDictionary *)dic
{
	[self.subTypes removeAllObjects];
	self.faultId = [[dic objectForKey:kHO_FIELD_FaultId] intValue];
	self.faultDetail = [dic objectForKey:kHO_FIELD_FaultName];
	NSArray *array = [dic objectForKey:kHO_FIELD_SubTypes];
	if(array)
	{
		for(int i = 0; i < [array count]; i ++)
		{
			NSDictionary *subDic = [array objectAtIndex:i];
			
			int subFaultId = [[subDic objectForKey:kHO_FIELD_FaultId] intValue];
			HOFaultCategoryEntity *entity = [[HOStaticDataMgr sharedInstance] getFaultCategoryEntityWithId:subFaultId];
			[entity parseDic:subDic];
			[self.subTypes addObject:entity];
			entity.index = i;
		}
	}
}
- (NSString *)getHybridTypeString
{
	if(self.deptEntity != nil)
	{
		return [NSString stringWithFormat:@"%@-%@", [HOUtils getValideString:self.deptEntity.departmentName], [HOUtils getValideString:self.faultDetail]];
	}
	else
	{
		return [HOUtils getValideString:self.faultDetail];
	}
}

- (void)dealloc
{
	self.faultDetail = nil;
	[self.subTypes removeAllObjects];
	self.subTypes = nil;
    self.selectedSubFaultGategoryEntity = nil;
	self.deptEntity = nil;
	[super dealloc];
}
@end
